
global user "dveracossio"
global dirdata "C:\Users\\$user\Dropbox\CCT BJP\data"
global dir1  "$dirdata\Final data"
global dir2  "$dirdata\Results\graphs"
global dir3  "$dirdata\Results\"
cd "$dir3"
use "$dir1\pooled_children.dta", clear
set sortseed 0.1
set more off
capture log close

**** Grouping variables by interest

*** Schooling

global schooling "bjp enroll atnd attend"
*** Children labor market outcomes

global child_labor "work w_hoursw "

*** Mother labor market outcomes

g age_head=age_m if hhmale==0
replace age_head=age_p if hhmale==1
g schooling_head=schooling_m if hhmale==0
replace schooling_head=schooling_p if hhmale==1

global controls " age_head hhmale urban spanish i.age  np  i.departamento#i.year c.np#i.year c.age#i.year i.year"

***** This Do Files Runs regressions for the analysis. 
****Diff in Diff

replace lschooling=. if lschooling<0
gen TS=ltau>=0
keep if  tau>-5




local replace replace
local sample1 (lschooling>=1 & lschooling<=8)
local spec1  TS i.lschooling  $controls

local enroll_lab "Enrollment"
local parm TS
local replace replace



foreach x in enroll {
sum `x' [w=factor] if ltau==-1 & `sample1'
local mean_dv=r(mean)
areg `x'  `spec1' [w=factor]  if `sample1' , a(departamento) cluster(municipio)
outreg2 using "$dir3\Table4", excel `replace' ctitle(``x'_lab') keep(`parm') less(0) nocons  bdec(3) adds(Clusters, e(N_clust), Mean DV, `mean_dv') alpha(0.01, 0.05, 0.1) addtext(Controls, NO, Municipality FE, NO, Group Trend, NO, Sample, 4-8th)
}

egen hogar=group(folio year)
egen avg_age=mean(age), by(hogar)
egen nenroll=total(enroll), by(hogar)
egen min=min(lschooling) ,by(hogar)
keep if min==lschooling
bysort hogar lschooling: g obs=_n
keep if obs==1
global controls " age_head hhmale urban spanish avg_age  np  i.departamento#i.year c.np#i.year c.avg_age#i.year i.year"
local replace append
foreach x in nenroll   {
sum `x' [w=factor] if ltau==-1  & `sample1'
local mean_dv=r(mean)
areg `x'  `spec1'  [w=factor] if `sample1'  , a(departamento) cluster(municipio)
outreg2 using "$dir3\Table4", excel `replace' ctitle(``x'_lab') keep(`parm') less(0) nocons  bdec(3) adds(Clusters, e(N_clust), Mean DV, `mean_dv') alpha(0.01, 0.05, 0.1) addtext(Controls, NO, Municipality FE, NO, Group Trend, NO, Sample, 4-8th)
}








use "$dir1\pooled_children.dta", clear
set sortseed 0.1
set more off
capture log close

**** Grouping variables by interest

*** Schooling

global schooling "bjp enroll atnd attend"
*** Children labor market outcomes

global child_labor "work whours "

*** Mother labor market outcomes

g age_head=age_m if hhmale==0
replace age_head=age_p if hhmale==1
g schooling_head=schooling_m if hhmale==0
replace schooling_head=schooling_p if hhmale==1

global controls " age_head hhmale urban spanish  age np  i.departamento#i.year c.np#i.year c.age#i.year i.year"

***** This Do Files Runs regressions for the analysis. 
****Diff in Diff

gen TS=tau>=0
keep if tau>-5

local replace replace
local sample1 (schooling>=1 & schooling<=8)
local spec1  TS i.schooling  $controls

local attend_lab "Attend"
local parm TS
local replace append

local work_lab "Works"
replace work=. if age<7
foreach x in attend work w_hoursw{
sum `x' [w=factor] if tau==-1 & `sample1'
local mean_dv=r(mean)
areg `x'  `spec1' [w=factor]  if `sample1' , a(departamento) cluster(municipio)
outreg2 using "$dir3\Table4", excel `replace' ctitle(``x'_lab') keep(`parm') less(0) nocons  bdec(3) adds(Clusters, e(N_clust), Mean DV, `mean_dv') alpha(0.01, 0.05, 0.1) addtext(Controls, NO, Municipality FE, NO, Group Trend, NO, Sample, 4-8th)
}


egen hogar=group(folio year)
egen nattend=total(attend), by(hogar)
egen ncwork=total(work), by(hogar)
egen ncworkh=total(w_hoursw), by(hogar)
egen avg_age=mean(age), by(hogar)
egen min=min(schooling) ,by(hogar)
keep if min==schooling
bysort hogar schooling: g obs=_n
keep if obs==1

global controls " age_head hhmale urban spanish  avg_age np  i.departamento#i.year c.np#i.year c.avg_age#i.year i.year"

foreach x in nattend ncwork  ncworkh {
sum `x' [w=factor] if tau==-1 & `sample1'
local mean_dv=r(mean)
areg `x'  `spec1' [w=factor] if `sample1' , a(departamento) cluster(municipio)
outreg2 using "$dir3\Table4", excel `replace' ctitle(``x'_lab') keep(`parm') less(0) nocons  bdec(3) adds(Clusters, e(N_clust), Mean DV, `mean_dv') alpha(0.01, 0.05, 0.1) addtext(Controls, NO, Municipality FE, NO, Group Trend, NO, Sample, 4-8th)
}




